﻿using MaterialDesignThemes.Wpf;
using project.B12.application.Ioc;
using project.B12.application.ViewModels.Dialogs;
using project.B12.Model.Enums;
using software.dll.user;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace project.B12.application.Views.Dialogs
{
    /// <summary>
    /// ExpirationTimeView.xaml 的交互逻辑
    /// </summary>
    public partial class ExpirationTimeView : UserControl
    {
        public string DialogHostName { get; internal set; }//对话框主机名

        public ExpirationTimeView(UserModel userModel)
        {
            InitializeComponent();
            var temp = this.DataContext as ExpirationTimeViewModel;
            temp.UserName = userModel.Name;
            temp.CurrentExpirationTime = userModel.ExpirationTime;
        }

        /// <summary>
        /// 打开对话框(更改过期时间)
        /// </summary>
        /// <param name="taskTemplate"></param>
        /// <param name="dialogHostName"></param>
        /// <returns></returns>
        public static async Task<ExpirationTimeEnum?> ExpirationTime(UserModel userModel, string dialogHostName = "Main")
        {
            if (DialogHost.IsDialogOpen(dialogHostName))
                return null;
            var expirationTimeView = new ExpirationTimeView(userModel)
            {
                DialogHostName = dialogHostName,
            };
            return (ExpirationTimeEnum?)await DialogHost.Show(expirationTimeView, dialogHostName);
        }
    }
}
